#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <mainui.h>
#include <QMessageBox>

/**
 *  登录窗口
 * @brief MainWindow::MainWindow
 * @param parent
 */
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->password->setEchoMode(QLineEdit::Password); // 设置密码框
}

MainWindow::~MainWindow()
{
    delete ui;
}

// 处理登录按钮点击事件
void MainWindow::on_login_btn_clicked()
{
    // 获取输入登录信息
    QString userNameStr = ui->username->text();
    QString passwordStr = ui->password->text();

    qDebug() << "username= " << userNameStr << " password= " << passwordStr;

    if (userNameStr.compare(QString::fromLocal8Bit("root")) == 0 &&
            passwordStr.compare(QString::fromLocal8Bit("123123")) == 0) {
        qDebug() << "登录成功!";
        this->close();
//        MainUI mainUi;
//        mainUi.show();
        MainUI *mu = new MainUI(this);
        mu->show();
        mu->setWelcome(userNameStr);
        mu->setUserInfo(userNameStr);

    } else {
        qDebug() << "输入的用户名或密码有误!";
        QMessageBox::about(this, "提示", "输入的用户名或密码有误!");
        on_cancel_btn_clicked();
    }

}

// 处理取消按钮点击事假
void MainWindow::on_cancel_btn_clicked()
{
    // 清除输入框输入的内容
    ui->username->clear();
    ui->password->clear();
}
